/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UI_Produccion.java
 *
 * Created on May 3, 2010, 1:16:20 PM
 */

package UI;

import Excepciones.BasesdeDatos;
import Excepciones.DinamicaDato;
import Excepciones.Sistema;
import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
import java.sql.SQLException;
import Modelo.BaseDato;
import robot_maker.Inventario;
import robot_maker.Manager;
import robot_maker.ResultSetTableModel;

/**
 *
 * @author CarlosScipione
 */
public class UI_Produccion extends javax.swing.JFrame {

    /** Creates new form UI_Produccion */
    public UI_Produccion() {
        initComponents();
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);


    }

    public void refrescar() {

try{
            try {
                BaseDato buscar = new BaseDato();
            } catch (CommunicationsException ex) {
                        Sistema.loggear(10, "LLENAR",
                        "COMUNICACION PERDIDA CON LA BASE DE DATOS",
                        UI_Clientes.class, "CommunicationsException");
            } catch (DinamicaDato ex) {
            }
            this.robot_table.setModel(new ResultSetTableModel("select " +
               "r.id \"Codigo\", r.nombre \"Nombre\", i.cantidad \"Cantidad\" "+
               "from ROBOT r, INVENTARIO i where r.id=i.robot_id and " +
               "i.accesorio_id is null"));
            if (this.robot_table.getRowCount() > 0) {
                this.robot_table.setRowSelectionInterval(0, 0);
            }

            this.accesorio_table.setModel(new ResultSetTableModel("select " +
               "a.id \"Codigo\", a.nombre \"Nombre\", i.cantidad \"Cantidad\" "+
               "from ACCESORIO a, INVENTARIO i where a.id=i.accesorio_id and "+
               "i.robot_id is null"));
            if (this.accesorio_table.getRowCount() > 0) {
                this.accesorio_table.setRowSelectionInterval(0, 0);
            }
        } catch (ClassNotFoundException ex) {
         Sistema.loggear(18, "refrescar", "SQL SYNTAXIS", Inventario.class,
                    "ClassNotFoundException");
        } catch (SQLException ex) {
        Sistema.loggear(18, "refrescar", "SQL SYNTAXIS", Inventario.class,
                    "SQLException");
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        robot_table = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        accesorio_table = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Inventario");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Inventario:");

        robot_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        robot_table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                robot_tableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(robot_table);

        jButton1.setText("+");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        accesorio_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        accesorio_table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                accesorio_tableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(accesorio_table);

        jLabel2.setText("Robots Disponibles:");

        jLabel3.setText("Accesorios Disponibles:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 274, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 274, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(jButton1)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(3, 3, 3)
                        .add(jLabel1)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel2))
                    .add(layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jScrollPane2, 0, 0, Short.MAX_VALUE)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void robot_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_robot_tableMouseClicked

}//GEN-LAST:event_robot_tableMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        addProduccion window = new addProduccion(this);
        window = (addProduccion) Manager.centra(window);
        window.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void accesorio_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_accesorio_tableMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_accesorio_tableMouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
         try {
            try {
                BaseDato buscar = new BaseDato();
            } catch (CommunicationsException ex) {
                        Sistema.loggear(10, "LLENAR",
                        "COMUNICACION PERDIDA CON LA BASE DE DATOS",
                        UI_Clientes.class, "CommunicationsException");
            } catch (DinamicaDato ex) {
            }
            this.robot_table.setModel(new ResultSetTableModel("select " +
               "r.id \"Codigo\", r.nombre \"Nombre\", i.cantidad \"Cantidad\" "+
               "from ROBOT r, INVENTARIO i where r.id=i.robot_id and " +
               "i.accesorio_id is null"));
            if (this.robot_table.getRowCount() > 0) {
                this.robot_table.setRowSelectionInterval(0, 0);
            }

            this.accesorio_table.setModel(new ResultSetTableModel("select " +
               "a.id \"Codigo\", a.nombre \"Nombre\", i.cantidad \"Cantidad\" "+
               "from ACCESORIO a, INVENTARIO i where a.id=i.accesorio_id and "+
               "i.robot_id is null"));
            if (this.accesorio_table.getRowCount() > 0) {
                this.accesorio_table.setRowSelectionInterval(0, 0);
            }
        } catch (ClassNotFoundException ex) {
        Sistema.loggear(18, "refrescar", "SQL SYNTAXIS", Inventario.class,
                    "ClassNotFoundException");
        } catch (SQLException ex) {
        Sistema.loggear(18, "refrescar", "SQL SYNTAXIS", Inventario.class,
                    "SQLException");
        }
    }//GEN-LAST:event_formWindowOpened

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UI_Produccion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable accesorio_table;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable robot_table;
    // End of variables declaration//GEN-END:variables

}
